package entities;

import java.io.Serializable;

import com.activity.MainAppActivity;
import com.activity.MapActivity;
import com.activity.R;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MyLocate implements Serializable{
	private String name;
	private String address;
	private double la,log;
	public String getName() {
		return name;
	}
	public MyLocate(){}
	public void setName(String name) {
		this.name = name;
	}
	public MyLocate(String name, String address, double la, double log) {
		super();
		this.name = name;
		this.address = address;
		this.la = la;
		this.log = log;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public double getLa() {
		return la;
	}
	public void setLa(double la) {
		this.la = la;
	}
	public double getLog() {
		return log;
	}
	public void setLog(double log) {
		this.log = log;
	}
	public void markOnMap()
	{
		MarkerOptions marker=new MarkerOptions();
		LatLng latlong=new LatLng(la,log);
		marker.position(latlong);
		marker.title(name+Locate.patternParse+getDistance()+MainAppActivity.unitDistance);
		marker.snippet(address);
		marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.mylocate));	
		MapActivity.googleMap.addMarker(marker).showInfoWindow();		
		 
	}
	public void moveCamera(){
		LatLng latlog=new LatLng(la, log);
		MapActivity.googleMap.moveCamera(CameraUpdateFactory.newLatLng(latlog));
		MapActivity.googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
	}
	public double getDistance()
	{
		LatLng locate=MainAppActivity.orginalLatl;
		double theta=locate.longitude-log;
		double dist=Math.sin(deg2rad(locate.latitude)) * Math.sin(deg2rad(la))
				+ Math.cos(deg2rad(locate.latitude)) * Math.cos(deg2rad(la)) * Math.cos(deg2rad(theta));
		dist=Math.acos(dist);
		dist=rad2deg(dist);
		dist=dist * 60; 
		dist=dist * 1852; 
		dist/=1000.0;
		dist*=100;
		dist=Math.round(dist)/100.0;
		return dist;
	}	
	// doi tu radian sang do
	private double rad2deg(double rad) {
		return rad * 180.0/Math.PI;
	}
	
	// doi tu do sang radian
	private double deg2rad(double deg) {
		return (deg*Math.PI/180.0);
	}	
}
